package P3;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class P3_lengthOfLongestSubstring {

    public static void main(String[] args) {

        System.out.println(new P3_lengthOfLongestSubstring().lengthOfLongestSubstring("abcabcbb"));
    }

    public int lengthOfLongestSubstring(String s) {

        int max = 0;

        for (int i = 0; i < s.length(); i++) {
            Set<Character> charSet = new HashSet<>();
            for (int j = i; j < s.length(); j++) {
                char charAt = s.charAt(j);
                if (!charSet.contains(charAt)) {
                    charSet.add(charAt);
                    max = max > charSet.size() ? max : charSet.size();
                } else {
                    break;
                }
            }
        }
        return max;
    }
}
